/*
 * @Author: jiutian
 * @Date: 2023-01-31 11:43:34
 * @LastEditTime: 2023-03-13 11:16:13
 * @LastEditors:
 */

const fs = require("fs");
const path = require("path");
module.exports = requireContext = (filePath) => {
  let routerFile = [];
  // 获取 router 文件夹下的 js 文件
  let files = fs.readdirSync(filePath);
  let filterlist = files.filter((v) => /\.js$/.test(v));

  filterlist.forEach((v) => {
    let item = {
      filename: null,
      fileUrl: null,
    };
    item.filename = v.split(".")[0];
    item.fileUrl = path.join(filePath, v);
    routerFile.push(item);
  });

  return routerFile;
};
